//
//  UIButton+Util.m
//
//  Created by SKY
//  Copyright © 翊sky. All rights reserved.
//

#import "UIButton+Util.h"
#import <UIButton+WebCache.h>

@implementation UIButton (Util)

//image,title
+(UIButton *)buttonWithLocalImage:(NSString *)image title:(NSString *)title titleColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize frame:(CGRect)frame target:(id)target sel:(SEL)selector{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    if (titleColor != nil) {
        [btn setTitleColor:titleColor forState:UIControlStateNormal];
    }
    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}

//backgroundImage
+(UIButton *)buttonWithLocalBgImage:(NSString *)bgImage frame:(CGRect)frame target:(id)target sel:(SEL)selector{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setBackgroundImage:[UIImage imageNamed:bgImage] forState:UIControlStateNormal];
    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    return btn;

}

+(UIButton *)buttonWithNetImage:(NSString *)imageURL title:(NSString *)title titleColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize frame:(CGRect)frame target:(id)target sel:(SEL)selector{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn buttonWithNetImage:imageURL];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    if (titleColor != nil) {
        [btn setTitleColor:titleColor forState:UIControlStateNormal];
    }
    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}

//backgroundImage
+(UIButton *)buttonWithNetBgImage:(NSString *)bgImageURL frame:(CGRect)frame target:(id)target sel:(SEL)selector{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn buttonWithNetBGImage:bgImageURL];
    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
    
}

-(void)buttonWithNetImage:(NSString *)netImageURL{
    
    NSURL *url = [NSURL URLWithString:netImageURL];
    [self sd_setImageWithURL:url forState:UIControlStateNormal];
}

-(void)buttonWithNetBGImage:(NSString *)netBGImageURL{
    
    NSURL *url = [NSURL URLWithString:netBGImageURL];
    [self sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
}

@end
